﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLayer.FindArtInfo;
using BusinessLayer.FindArtInfo.Entities;
using CommandLib;
using FindArtInfo.Common;
using FindArtInfo.Models;
using Resources;

namespace FindArtInfo.Controllers
{
    public class SubmitYourSiteController : MultiBase
    {
        //
        // GET: /SubmitYourSite/

        private PageSubmitYourSiteModel InitPageSubmitYourSiteModel()
        {
            PageSubmitYourSiteModel model = new PageSubmitYourSiteModel();
            model.ListCate = new ArtLinksCategoryBL().GetAll();
            return model;
        }

        [RestoreModelStateFromTempData]
        public ActionResult Index()
        {
            return View(InitPageSubmitYourSiteModel());
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        [SetTempDataModelState]
        public ActionResult Index(PageSubmitYourSiteModel model)
        {
            if(!ModelState.IsValid)
            {
                return View(InitPageSubmitYourSiteModel());
            }
            ArtLinksCategory cate = new ArtLinksCategoryBL().GetById(model.CateId);
            string subject = "From FindArtInfo.com - regarding the submission of your link";
            string content = string.Format("URL: {0}" +
                                     "<p>Headline: {1}" +
                                     "<p>Description :{2}" +
                                     "<p>Category :{3}" +
                                     "<p>Email :{4}" +
                                     "<p>Country :{5}" +
                                     "<p>Reciprocal Link URL: {6}",
                                    model.Url, model.Headline, model.ShortDes, cate.Category, model.Email, model.Country, model.ReciprocalLinkUrl);
            int result = Utils.SendMail(Config.FromEmail, Config.DiplayFromName, Config.PassFromEmail, model.Email,
                                        model.Email, Config.EmailCC, subject, content, Config.Host, Convert.ToInt32(Config.Port));
            ModelState.AddModelError("MessageResult", string.Format(Multi.PageSubmitYourSiteSuccess, Utils.GetUrlByLanguage(CookiesStore.GetCookies(Constants.Cookie.COOKIE_LANGUAGE))));
            //return Redirect("~/submit-your-site.html");
            return Redirect(string.Format("~/{0}/submit-your-site.html", Utils.GetUrlByLanguage(CookiesStore.GetCookies(Constants.Cookie.COOKIE_LANGUAGE))));
        }
    }
}
